<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="btn">点击</button>
    <script>
        const btn = document.getElementById('btn')
        const clickFn =()=>{
            console.log('点击了');
        }
        btn.addEventListener('click',throttle(clickFn,1000))

        function debounce(fn,delay){
            let timer = null
            return function(...args){
                clearTimeout(timer)
                timer =  setTimeout(()=>{
                    fn.call(this,...args)
                },delay)
            }
        }
        function throttle(fn,delay){
            let preTime = 0
            return function(...args){
                let nowTime = Date.now()
                if(nowTime - preTime >= delay){
                    fn.call(this,...args)
                    preTime = nowTime
                }
            }
        }

    </script>
</body>
</html>